package bscorp.appbase.bmo;


import android.util.Log;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import bscorp.appbase.AppManager;
import bscorp.appbase.db.M4Dao;
import bscorp.appbase.model.Order;

/**
 * description: 用户数据处理
 * autour: jamie
 * date:   2017/9/13.
 * update:
 * version:
 */
public class OrderBmo {
    private static String TAG = "OrderBmo";

    /**
     * 保存工单信息
     *
     * @param model
     */
    public boolean saveOrderInfo(Order model) {
        try {
            M4Dao.getInstance(AppManager.context).add(model, Order.class);
            return true;
        } catch (SQLException e) {
            Log.e("jamie", "---saveUserInfo  error---");
            return false;
        }
    }

    /**
     * 修改工单信息
     *
     * @param model
     */
    public boolean updateOrder(Order model) {
        try {
            M4Dao.getInstance(AppManager.context).update(model, Order.class);
            return true;
        } catch (SQLException e) {
            Log.e("jamie", "---saveDevice error---");
            return false;
        }
    }

    /**
     * 读取用户信息
     *
     * @return
     */
    public List<Order> getOrderByRepaireUserId(String repaireUserId) {
        Map<String, String> map = new HashMap<String, String>();
        map.put("repaireUserId", repaireUserId);
        return getOrderByValues(map);
    }

    /**
     * 读取用户信息
     *
     * @return
     */
    public List<Order> getOrderByRepaireUserIdAndType(String repaireUserId, String type) {
        Map<String, String> map = new HashMap<String, String>();
        map.put("repaireUserId", repaireUserId);
        map.put("type", type);
        return getOrderByValues(map);
    }

    /**
     * 读取用户信息
     *
     * @return
     */
    public List<Order> getOrderByReportUserIdAndType(String reportUserId, String type) {
        Map<String, String> map = new HashMap<String, String>();
        map.put("reportUserId", reportUserId);
        map.put("type", type);
        return getOrderByValues(map);
    }

    /**
     * 读取用户信息
     *
     * @return
     */
    public List<Order> getOrderByType(String type) {
        Map<String, String> map = new HashMap<String, String>();
        map.put("type", type);
        return getOrderByValues(map);
    }

    /**
     * 读取用户信息
     *
     * @return
     */
    public List<Order> getOrderByeportUserId(String reportUserId) {
        Map<String, String> map = new HashMap<String, String>();
        map.put("reportUserId", reportUserId);
        return getOrderByValues(map);
    }

    private List<Order> getOrderByValues(Map<String, String> map) {
        List<Order> list = null;
        try {
            list = M4Dao.getInstance(AppManager.context).getByValues(map, Order.class);
        } catch (SQLException e) {
            Log.e("jamie", "---getUserInfo error---" + e.getMessage());
        }
        return list;
    }
}
